<?php
	/**
	 * @package My QCubed Application
	 * @subpackage Drafts
	 *
	 */
	class SampleTitlesListPanel extends QPanel {
		// Local instance of the Meta DataGrid to list SampleTitleses
                public $mctSampleTitles;
                public $pnlSampleTitleEdit;

		public $dtgSampleTitles;
                public $objSample;
		// Other public QControls in this panel
		public $btnCreateNew;
		public $pxyEdit;

		// Callback Method Names
		protected $strSetEditPanelMethod;
		protected $strCloseEditPanelMethod;


		public function __construct($objParentObject, $objSample, $strCloseEditPanelMethod, $strControlId = null) {
			// Call the Parent
			try {
				parent::__construct($objParentObject, $strControlId);
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
                        $this->objSample = $objSample;
                        
			// Record Method Callbacks
			$this->strCloseEditPanelMethod = $strCloseEditPanelMethod;

                        $this->pnlSampleTitleEdit = new QePanel($this);
                        $this->pnlSampleTitleEdit->AutoRenderChildren = true;
                        $this->pnlSampleTitleEdit = new SampleTitlesEditPanel($this,"ClosePanel");

			// Setup the Template
			$this->Template = __DOCROOT__ . __SAMPLES__ . '/tpl/SampleTitlesListPanel.tpl.php';


			// Instantiate the Meta DataGrid
			$this->dtgSampleTitles = new SampleTitlesDataGrid($this);

			// Style the DataGrid (if desired)
			$this->dtgSampleTitles->CssClass = 'datagrid';
			$this->dtgSampleTitles->AlternateRowStyle->CssClass = 'alternate';

			// Add Pagination (if desired)
			$this->dtgSampleTitles->Paginator = new QPaginator($this->dtgSampleTitles);
			$this->dtgSampleTitles->ItemsPerPage = 8;
                        
                        $this->dtgSampleTitles->AdditionalConditions = QQ::Equal(QQN::SampleTitles()->SampleId, $_SESSION["SampleId"]) ;

			// Use the MetaDataGrid functionality to add Columns for this datagrid

			// Create an Edit Column
			$this->pxyEdit = new QControlProxy($this);
			
			// #AND#: Add row count
                        // #AND#: Add isbn
			//$this->dtgSampleTitles->MetaAddColumn(QQN::SampleTitles()->Sample);
                        $this->dtgSampleTitles->AddColumn(new QDataGridColumn('Row Number', '<?= ($_CONTROL->CurrentRowIndex + 1) ?>'));
                        $this->dtgSampleTitles->MetaAddColumn(QQN::SampleTitles()->Title->Isbn );
			$this->dtgSampleTitles->MetaAddColumn(QQN::SampleTitles()->Title->Title);
			$this->dtgSampleTitles->MetaAddColumn('Notes');
			//#AND$: Status per record

			// Setup the Create New button
			$this->btnCreateNew = new QButton($this);
			$this->btnCreateNew->Text = QApplication::Translate('Create a New') . ' ' . QApplication::Translate('SampleTitles');
			$this->btnCreateNew->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCreateNew_Click'));
		}
                public function Set_Sample(){
                    $this->dtgSampleTitles->AdditionalConditions = QQ::Equal(QQN::SampleTitles()->SampleId, $this->objSample->Id) ;
                }
		public function pxyEdit_Click($strFormId, $strControlId, $strParameter) {
			$strParameterArray = explode(',', $strParameter);
			$objEditPanel = new SampleTitlesEditPanel($this, $this->strCloseEditPanelMethod, $strParameterArray[0]);

			$strMethodName = $this->strSetEditPanelMethod;
			$this->objForm->$strMethodName($objEditPanel);
		}
                public function ClosePanel($ClosePanel, $RefreshPanel=null){
                        $this->$ClosePanel->RemoveChildControls(true);
                        $this->$ClosePanel->Visible = false;

                        if ($RefreshPanel)
                            $this->$RefreshPanel->Refresh();
                        $this->pnlSampleTitleEdit = new SampleTitlesEditPanel($this,"ClosePanel");
                }

                public function SetEditPane($objPanel , $objParent) {
                    $a=1;
                }
                //$this->tabMain->ChangeTabById(1);
        


	}
?>